package club.xinghe.biz;

import club.xinghe.dao.AdminDao;
import club.xinghe.entity.Admin;
import club.xinghe.entity.Score;
import club.xinghe.entity.Yx;
import club.xinghe.entity.Zy;
import club.xinghe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明:对管理员进行操作的业务
 *
 * @姚文斌/刘艺广
 * @create 2019-09-28 下午 6:21
 */
public class AdminBiz {
    public  Admin getAdminById(int b){
        SqlSession session = SqlSessionFactoryUtil.getSqlSession();
        AdminDao adminDao= session.getMapper(AdminDao.class);
        return adminDao.getAdminById(b);
    }
    //管理员登录
    public Admin adminLogin(Admin admin){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        AdminDao adminDao=session.getMapper(AdminDao.class);
        return adminDao.adminLogin(admin);
    }
    //所有院系
    public List getAllYx(){
        SqlSession session = SqlSessionFactoryUtil.getSqlSession();
        List<Yx> yxList=null;
        try {
            AdminDao adminDao=session.getMapper(AdminDao.class);
            yxList=adminDao.getAllYx();
        }finally {
            session.close();
        }
        return yxList;
    }

    //所有年级
    public List getAllGrade(){
        SqlSession session = SqlSessionFactoryUtil.getSqlSession();
        List<Yx> gradeList=null;
        try {
            AdminDao adminDao=session.getMapper(AdminDao.class);
            gradeList=adminDao.getAllGrade();
        }finally {
            session.close();
        }
        return gradeList;
    }

    //根据院系查询专业
    public List getZyByYid(int yId){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Zy> zyList=null;
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            zyList=adminDao.getZyByYid(yId);
        }finally {
            session.close();
        }
        return zyList;
    }

    //根据年级id查询成绩
    public List getScoreByGid(Score score){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Score> scoreList=null;
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            scoreList=adminDao.getScoreByGid(score);
        }finally {
            session.close();
        }
        return scoreList;
    }

    //根据院系id查询成绩
    public List getScoreByYid(Score score){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Score> scoreList=null;
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            scoreList=adminDao.getScoreByYid(score);
        }finally {
            session.close();
        }
        return scoreList;
    }

    //根据专业id查询成绩
    public List getScoreByZid(Score score){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Score> scoreList=null;
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            scoreList=adminDao.getScoreByZid(score);
        }finally {
            session.close();
        }
        return scoreList;
    }

    //查询年级平均分
    public List getGradeAvg(int gid){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Map> avgList=null;
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            avgList=adminDao.getGradeAvg(gid);
        }finally {
            session.close();
        }
        return avgList;
    }

    public List getYxAvg(int gid,int yId){
        SqlSession session=SqlSessionFactoryUtil.getSqlSession();
        List<Map> avgList=null;
        Map map=new HashMap();
        map.put("gid",gid);
        map.put("yId",yId);
        try{
            AdminDao adminDao=session.getMapper(AdminDao.class);
            avgList=adminDao.getYxAvg(map);
        }finally {
            session.close();
        }
        return avgList;
    }
}
